version 14.2
set more off
set matsize 11000
set seed 12345
clear all
clear mata

***********************************************************************************************************************
* THIS ROUTINE GENERATES FIGURES VII OF WASEEM (2020) ROLE OF WITHHOLDING ...
***********************************************************************************************************************

/* ENTRY */
*------------

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
bys						regno:egen entry=min(taxperiod)	
duplicates				drop regno, force
keep					entry taxperiod fy item_cd business_sts
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g						treat=(business_sts=="1")
g						one=1
bys						entry treat:egen nentrants=sum(one)
g						period=mofd(entry)
keep					if entry>=d(01jul1998) & entry<d(01jul2005)
qui						sum period
replace					period=period-r(min)+1
duplicates				drop entry treat, force
drop					business_sts item_cd ind one
reshape					wide nentrants, i(period) j(treat)
ren						nentrants0 nimport
ren						nentrants1 nmanuf
g						diff=nmanuf-nimport
g						percentdiff=diff
g						diff_j=diff
replace					diff_j=0 if entry<d(01jan2002)

/* BOOTSTRAP FOR STANDARD ERROR */

mata
								nmanuf=st_data(.,"nmanuf")
								nimport=st_data(.,"nimport")
								diff_j=st_data(.,"diff_j")
								m=length(nmanuf)
								nboot=1000
								b_boot=J(m,nboot,0)
								se=J(m,1,0)
								for (j=1; j<=nboot; j++)
								{
									error_j=jumble(diff_j)
									nmanufc_j=nmanuf+error_j
									percentdiff_j=(nmanufc_j:-nimport)
									b_boot[,j]=percentdiff_j
								}
								for (i=1; i<=m; i++)
								{
									se[i]=sqrt(quadvariance(b_boot[i,]'))
								}
								st_matrix("se",se)
end
svmat 					se, names(se)
g						cil=percentdiff-1.96*se
g						cih=percentdiff+1.96*se
#d						;
twoway  				(rarea cil cih period,sort color(gs14))
						(connected  percentdiff period, sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o)),
						xtitle("Month of the Year") xscale(titlegap(*10))
						xlabel(1 "1998" 13 "1999" 25 "2000" 37 "2001" 49 "2002" 61 "2003" 73 "2004" 85 "2005")
						yscale(r(0))  yscale(titlegap(*10)) ytitle("Difference-in-Differences Coefficient") 
						xline(13 25, lpatter(dash) lcolor(green)) ylabel(-500(500)2000) 
						legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") order(2 1))
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white);
graph 					export "$project_output\DD_Entry_MVsI.eps", replace;
#d						cr

#d;
twoway  				(connected  nmanuf period,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o))
						(connected  nimport period,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(o) lpattern(shortdash)),
						xlabel(1 "1998" 13 "1999" 25 "2000" 37 "2001" 49 "2002" 61 "2003" 73 "2004" 85 "2005")
						xline(13 25, lpatter(dash) lcolor(green)) ylabel(-500(500)2000) 
						xtitle("Month of the Year") xscale(titlegap(*10))
						ytitle(Number of Firms, alignment(bottom)) yscale(r(0))  yscale(titlegap(*10))
						legend(region(style(none)) label(1 "Manufacturers") label(2 "Importers") rows(1)) 
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white); 	
graph 					export "$project_output\Entry_MVsIs.eps", replace;
#d						cr

/* REGISTRATIONS */
*------------------

clear					all
clear					mata
use 			 		"$project_data\Master Short Updated Nov 2011.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
keep					regno business_sts item_cd date_comm*
g						rmonth=mofd(date_comm)
g						treat=business_sts=="1"
g						one=1
bys						rmonth treat:egen nregism=sum(one)
keep					if date_comm>=d(01jul1998) & date_comm<d(01jul2005)
duplicates				drop rmonth treat, force
g						period=rmonth
qui						sum period
replace					period=period-r(min)+1
keep					rmonth treat nregism period 
reshape					wide nregism, i(period) j(treat)
ren						nregism0 nimport
ren						nregism1 nmanuf
g						diff=nmanuf-nimport
g						percentdiff=diff
g						diff_j=diff
g 						date=dofm(rmonth)
replace					diff_j=0 if date<d(01jan2002)

/* BOOTSTRAP FOR STANDARD ERROR */

mata
								nmanuf=st_data(.,"nmanuf")
								nimport=st_data(.,"nimport")
								diff_j=st_data(.,"diff_j")
								m=length(nmanuf)
								nboot=1000
								b_boot=J(m,nboot,0)
								se=J(m,1,0)
								for (j=1; j<=nboot; j++)
								{
									error_j=jumble(diff_j)
									nmanufc_j=nmanuf+error_j
									percentdiff_j=(nmanufc_j:-nimport)
									b_boot[,j]=percentdiff_j
								}
								for (i=1; i<=m; i++)
								{
									se[i]=sqrt(quadvariance(b_boot[i,]'))
								}
								st_matrix("se",se)
end
svmat 					se, names(se)
g						cil=percentdiff-1.96*se
g						cih=percentdiff+1.96*se
#d						;
twoway  				(rarea cil cih period,sort color(gs14))
						(connected  percentdiff period,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o)),
						xtitle("Month of the Year") xscale(titlegap(*10))
						xlabel(1 "1998" 13 "1999" 25 "2000" 37 "2001" 49 "2002" 61 "2003" 73 "2004" 85 "2005")
						yscale(r(0))  yscale(titlegap(*10)) ytitle("Difference-in-Differences Coefficient") 
						xline(13 25, lpatter(dash) lcolor(green)) ylabel(-500(500)2000)
						legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") order(2 1))
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white);
graph 					export "$project_output\DD_Registration_MVsI.eps", replace;
#d						cr
#d;
twoway  				(connected  nmanuf period,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o))
						(connected  nimport period,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(o) lpattern(shortdash)),
						xlabel(1 "1998" 13 "1999" 25 "2000" 37 "2001" 49 "2002" 61 "2003" 73 "2004" 85 "2005")
						xline(13 25, lpatter(dash) lcolor(green)) ylabel(-500(500)2000) 
						xtitle("Month of the Year") xscale(titlegap(*10))
						ytitle(Number of Firms, alignment(bottom)) yscale(r(0))  yscale(titlegap(*10))
						legend(region(style(none)) label(1 "Manufacturers") label(2 "Importers") rows(1)) 
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white); 	
graph 					export "$project_output\Registration_MVsIs.eps", replace;
#d						cr

/* REAL ENTRY */

clear					all
clear					mata
use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
g						active=(sale_ag>0 | purch_ag>0 | output>0 | input>0)
keep					if active==1
bys						regno:egen entry=min(taxperiod)	
duplicates				drop regno, force
keep					entry taxperiod fy item_cd business_sts
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g						treat=(business_sts=="1")
g						one=1
bys						entry treat:egen nentrants=sum(one)
g						period=mofd(entry)
keep					if entry>=d(01jul1998) & entry<d(01jul2005)
qui						sum period
replace					period=period-r(min)+1
duplicates				drop entry treat, force
drop					business_sts item_cd ind one
reshape					wide nentrants, i(period) j(treat)
ren						nentrants0 nimport
ren						nentrants1 nmanuf
g						diff=nmanuf-nimport
g						percentdiff=diff
g						diff_j=diff
replace					diff_j=0 if entry<d(01jan2002)

/* BOOTSTRAP FOR STANDARD ERROR */

mata
								nmanuf=st_data(.,"nmanuf")
								nimport=st_data(.,"nimport")
								diff_j=st_data(.,"diff_j")
								m=length(nmanuf)
								nboot=1000
								b_boot=J(m,nboot,0)
								se=J(m,1,0)
								for (j=1; j<=nboot; j++)
								{
									error_j=jumble(diff_j)
									nmanufc_j=nmanuf+error_j
									percentdiff_j=(nmanufc_j:-nimport)
									b_boot[,j]=percentdiff_j
								}
								for (i=1; i<=m; i++)
								{
									se[i]=sqrt(quadvariance(b_boot[i,]'))
								}
								st_matrix("se",se)
end
svmat 					se, names(se)
g						cil=percentdiff-1.96*se
g						cih=percentdiff+1.96*se
#d						;
twoway  				(rarea cil cih period,sort color(gs14))
						(connected  percentdiff period,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o)),
						xtitle("Month of the Year") xscale(titlegap(*10))
						xlabel(1 "1998" 13 "1999" 25 "2000" 37 "2001" 49 "2002" 61 "2003" 73 "2004" 85 "2005")
						yscale(r(0))  yscale(titlegap(*10)) ytitle("Difference-in-Differences Coefficient") 
						xline(13 25, lpatter(dash) lcolor(green)) ylabel(-500(500)2000)
						legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") order(2 1))
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white);
graph 					export "$project_output\DD_Entry_Active_MVsI.eps", replace;
#d						cr
#d;
twoway  				(connected  nmanuf period,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o))
						(connected  nimport period,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(o) lpattern(shortdash)),
						xlabel(1 "1998" 13 "1999" 25 "2000" 37 "2001" 49 "2002" 61 "2003" 73 "2004" 85 "2005")
						xline(13 25, lpatter(dash) lcolor(green)) ylabel(-500(500)2000) 
						xtitle("Month of the Year") xscale(titlegap(*10))
						ytitle(Number of Firms, alignment(bottom)) yscale(r(0))  yscale(titlegap(*10))
						legend(region(style(none)) label(1 "Manufacturers") label(2 "Importers") rows(1)) 
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white); 	
graph 					export "$project_output\Entry_Active_MVsIs.eps", replace;
#d						cr

